import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'app/theme/colors.dart';

class ThemeController extends GetxController {
  // 使用 RxBool 来监听夜间模式状态的变化
  final _isDarkMode = false.obs;
  bool get isDarkMode => _isDarkMode.value;
  set isDarkMode(bool value) => _isDarkMode.value = value;

  // 切换夜间模式的方法
  void toggleTheme() {
    isDarkMode = !isDarkMode;
    Get.changeTheme(isDarkMode ? darkTheme : lightTheme);
  }
}


final ThemeData lightTheme = ThemeData(
  brightness: Brightness.light,
  canvasColor: Colors.transparent, // 为所有 Material 小部件设置默认颜色
  scaffoldBackgroundColor: PageBackgroundColor,
  appBarTheme: const AppBarTheme(
    elevation: 1,//隐藏底部阴影分割线
    centerTitle: true,//标题是否居中 安卓上有效ios默认居中
    toolbarHeight: 44,
    iconTheme: IconThemeData(color: Colors.black),
    backgroundColor: Colors.white, // 设置导航栏背景颜色为白色
    foregroundColor: Colors.white, /// 影响导航标题颜色,
    surfaceTintColor: Colors.white,
    titleTextStyle: TextStyle(color: Colors.black, fontSize: 20), // 设置标题文本颜色
  ),
  dialogTheme: const DialogTheme(
    shadowColor: Colors.white,
    backgroundColor: Colors.white, // 设置对话框的背景颜色为白色
    surfaceTintColor: Colors.white,
  ),
);


final ThemeData darkTheme = ThemeData(
  brightness: Brightness.dark,
  canvasColor: Colors.transparent, // 为所有 Material 小部件设置默认颜色
  scaffoldBackgroundColor: Colors.black,
  appBarTheme: const AppBarTheme(
    elevation: 1,//隐藏底部阴影分割线
    centerTitle: true,//标题是否居中 安卓上有效ios默认居中
    toolbarHeight: 44,
    iconTheme: IconThemeData(color: Colors.white),
    backgroundColor: Colors.white, // 设置导航栏背景颜色为白色
    foregroundColor: Colors.white, /// 影响导航标题颜色,
    surfaceTintColor: Colors.white,
    titleTextStyle: TextStyle(color: Colors.black, fontSize: 20), // 设置标题文本颜色
  ),
  dialogTheme: const DialogTheme(
    shadowColor: Colors.white,
    backgroundColor: Colors.white, // 设置对话框的背景颜色为白色
    surfaceTintColor: Colors.white,
  ),
);





setupButtonTheme() {
  return const ButtonThemeData(
    buttonColor: Colors.white,
    disabledColor: Colors.grey,
    focusColor: Colors.white,
    hoverColor: Colors.white,
    highlightColor: Colors.white,
    splashColor: Colors.white,
  );
}

setupElevatedButtonTheme() {
  return ElevatedButtonThemeData(
    style: ElevatedButton.styleFrom(
      // foregroundColor: ThemeColor,
      backgroundColor: Colors.white,
      shadowColor: Colors.transparent,
      surfaceTintColor: Colors.transparent,
      //disabledBackgroundColor: Colors.white,
      //disabledForegroundColor: Colors.amber,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
    ),
  );
}

BottomAppBarTheme setupBottomAppBarTheme() {
  return const BottomAppBarTheme(
    color: Colors.white,
    elevation: 0,
    shape: CircularNotchedRectangle(),  // Ensure shape is not null
  );
}

setupBottomNavigationBarTheme() {
  return const BottomNavigationBarThemeData(
    backgroundColor: Colors.white,
    selectedItemColor: Colors.black,
    unselectedItemColor: Colors.grey,
    elevation: 0,
    type: BottomNavigationBarType.fixed,
    showUnselectedLabels: true,
    showSelectedLabels: true,
    selectedIconTheme: IconThemeData(color: Colors.black),
    unselectedIconTheme: IconThemeData(),
    selectedLabelStyle: TextStyle(color: Colors.black),
    unselectedLabelStyle: TextStyle(color: Colors.grey),
  );
}




setupRefresh() {
  EasyRefresh.defaultHeaderBuilder = () => const ClassicHeader(
    dragText: "下拉刷新",
    armedText: "松开立即刷新",
    readyText: "刷新中...",
    processingText: "刷新中...",
    processedText: "刷新成功",
    noMoreText: "没有更多",
    failedText: "刷新失败",
    messageText: "最后更新于 %T",
    // dragText: 'Pull to refresh'.tr,
    // armedText: 'Release ready'.tr,
    // readyText: 'Refreshing...'.tr,
    // processingText: 'Refreshing...'.tr,
    // processedText: 'Succeeded'.tr,
    // noMoreText: 'No more'.tr,
    // failedText: 'Failed'.tr,
    // messageText: 'Last updated at %T'.tr,
  );
  EasyRefresh.defaultFooterBuilder = () => const ClassicFooter(
    dragText: "上拉刷新",
    armedText: "松开立即刷新",
    readyText: "刷新中...",
    processingText: "刷新中...",
    processedText: "刷新成功",
    noMoreText: "没有更多",
    failedText: "刷新失败",
    messageText: "最后更新于 %T",
    // dragText: 'Pull to load'.tr,
    // armedText: 'Release ready'.tr,
    // readyText: 'Loading...'.tr,
    // processingText: 'Loading...'.tr,
    // processedText: 'Succeeded'.tr,
    // noMoreText: 'No more'.tr,
    // failedText: 'Failed'.tr,
    // messageText: 'Last updated at %T'.tr,
  );
}
